package pe.sonrisas.tools.view;


import Complementos.Conexion_BD;
import Complementos.Validar;
import Complementos.Visual;
import Control.ControlOdontologo;
import Control.ControlReserva;
import java.sql.ResultSet;
import java.util.Calendar;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
/*
  frmRegistrarPaciente.java

    Created on 22/08/2011,  22:29  PM.
    Programador         :   Diego Alvarado / Bruno Alvarado
    Descripcion         :   Formulario de reporte de Reservas realizadas .
    Última modificación :   25/08/2011 , 04:46 PER
    Observaciones       :   

 */
public class frmReporteReservas extends javax.swing.JFrame {

    /** Creates new form frmReporteReservas */

    Conexion_BD co = new Conexion_BD();
    ResultSet rs = null;
    Validar validar=new Validar();
    frmReservaCita reserva=new frmReservaCita(this, true);
    Vector<Vector> odontologos = new Vector<Vector>();

    static private frmReporteReservas objeto = null;

    private frmReporteReservas() {
        initComponents();
        this.setIconImage(new ImageIcon(getClass().getResource("/pe/sonrisas/tools/imagenes/comun/logo1.png")).getImage());
        Calendar c=comboFechaInicio.getSelectedDate();
        comboFechaInicio.setSelectedDate(c);
        cargarOdontologos();
    }

   static public frmReporteReservas getInstancia(){
        if (objeto == null){
            objeto = new frmReporteReservas();
        }
        return objeto;
    }



    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        btnBuscar = new javax.swing.JButton();
        comboMostrar = new javax.swing.JComboBox();
        jSeparator1 = new javax.swing.JSeparator();
        comboFechaInicio = new datechooser.beans.DateChooserCombo();
        comboFechaFinal = new datechooser.beans.DateChooserCombo();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        comboDr = new javax.swing.JComboBox();
        jToolBar1 = new javax.swing.JToolBar();
        btnEditarReserva = new javax.swing.JButton();
        btnCancelarReserva = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        lblContador = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblReporte = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("..:: Sonrisas Tools :..    Reporte de reservas");

        jPanel1.setBackground(new java.awt.Color(204, 204, 255));

        jPanel2.setBackground(new java.awt.Color(204, 204, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 153)), "Reporte de reservas", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tunga", 0, 24), new java.awt.Color(255, 255, 204))); // NOI18N
        jPanel2.setPreferredSize(new java.awt.Dimension(801, 635));

        btnBuscar.setText("Buscar");
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        comboMostrar.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Todas", "Activas", "Canceladas" }));

        comboFechaInicio.setCurrentView(new datechooser.view.appearance.AppearancesList("Grey",
            new datechooser.view.appearance.ViewAppearance("custom",
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(0, 0, 0),
                    new java.awt.Color(0, 0, 255),
                    false,
                    true,
                    new datechooser.view.appearance.swing.ButtonPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(0, 0, 0),
                    new java.awt.Color(0, 0, 255),
                    true,
                    true,
                    new datechooser.view.appearance.swing.ButtonPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(0, 0, 255),
                    new java.awt.Color(0, 0, 255),
                    false,
                    true,
                    new datechooser.view.appearance.swing.ButtonPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(128, 128, 128),
                    new java.awt.Color(0, 0, 255),
                    false,
                    true,
                    new datechooser.view.appearance.swing.LabelPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(0, 0, 0),
                    new java.awt.Color(0, 0, 255),
                    false,
                    true,
                    new datechooser.view.appearance.swing.LabelPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(0, 0, 0),
                    new java.awt.Color(255, 0, 0),
                    false,
                    false,
                    new datechooser.view.appearance.swing.ButtonPainter()),
                (datechooser.view.BackRenderer)null,
                false,
                true)));
    comboFechaInicio.setNothingAllowed(false);
    comboFechaInicio.setFormat(2);
    comboFechaInicio.setBehavior(datechooser.model.multiple.MultyModelBehavior.SELECT_SINGLE);

    comboFechaFinal.setCurrentView(new datechooser.view.appearance.AppearancesList("Grey",
        new datechooser.view.appearance.ViewAppearance("custom",
            new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                new java.awt.Color(0, 0, 0),
                new java.awt.Color(0, 0, 255),
                false,
                true,
                new datechooser.view.appearance.swing.ButtonPainter()),
            new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                new java.awt.Color(0, 0, 0),
                new java.awt.Color(0, 0, 255),
                true,
                true,
                new datechooser.view.appearance.swing.ButtonPainter()),
            new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                new java.awt.Color(0, 0, 255),
                new java.awt.Color(0, 0, 255),
                false,
                true,
                new datechooser.view.appearance.swing.ButtonPainter()),
            new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                new java.awt.Color(128, 128, 128),
                new java.awt.Color(0, 0, 255),
                false,
                true,
                new datechooser.view.appearance.swing.LabelPainter()),
            new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                new java.awt.Color(0, 0, 0),
                new java.awt.Color(0, 0, 255),
                false,
                true,
                new datechooser.view.appearance.swing.LabelPainter()),
            new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                new java.awt.Color(0, 0, 0),
                new java.awt.Color(255, 0, 0),
                false,
                false,
                new datechooser.view.appearance.swing.ButtonPainter()),
            (datechooser.view.BackRenderer)null,
            false,
            true)));
comboFechaFinal.setNothingAllowed(false);
comboFechaFinal.setLocale(new java.util.Locale("es", "PE", ""));
comboFechaFinal.setBehavior(datechooser.model.multiple.MultyModelBehavior.SELECT_SINGLE);

jLabel1.setText("Desde");

jLabel2.setText("Hasta");

jLabel3.setText("Mostrar");

jLabel4.setText("Odontólogo:");

jToolBar1.setFloatable(false);
jToolBar1.setRollover(true);

btnEditarReserva.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pe/sonrisas/tools/imagenes/comun/edit_reserva.png"))); // NOI18N
btnEditarReserva.setText("Editar reserva");
btnEditarReserva.setFocusable(false);
btnEditarReserva.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
btnEditarReserva.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
btnEditarReserva.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
        btnEditarReservaActionPerformed(evt);
    }
    });
    jToolBar1.add(btnEditarReserva);

    btnCancelarReserva.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pe/sonrisas/tools/imagenes/comun/cancel_reserva.png"))); // NOI18N
    btnCancelarReserva.setText("Cancelar reserva");
    btnCancelarReserva.setFocusable(false);
    btnCancelarReserva.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
    btnCancelarReserva.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    btnCancelarReserva.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnCancelarReservaActionPerformed(evt);
        }
    });
    jToolBar1.add(btnCancelarReserva);

    jLabel5.setText("Reservas encontradas:");

    lblContador.setText("0");

    tblReporte.setModel(new javax.swing.table.DefaultTableModel(
        new Object [][] {
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null, null}
        },
        new String [] {
            "Fecha", "Hora", "Paciente", "Tel", "Cel", "Tratamiento", "Estado", "idreserva"
        }
    ) {
        boolean[] canEdit = new boolean [] {
            true, true, true, true, true, true, true, false
        };

        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return canEdit [columnIndex];
        }
    });
    jScrollPane1.setViewportView(tblReporte);

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel2Layout.createSequentialGroup()
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 872, Short.MAX_VALUE))
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGap(44, 44, 44)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel3)
                        .addComponent(jLabel1))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(comboFechaInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(comboMostrar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel2)
                        .addComponent(jLabel4))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(comboDr, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(comboFechaFinal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGap(18, 18, 18)
                    .addComponent(btnBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE))
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 872, Short.MAX_VALUE)))
            .addContainerGap())
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                    .addGap(0, 669, Short.MAX_VALUE)
                    .addComponent(jLabel5)
                    .addGap(18, 18, 18)
                    .addComponent(lblContador)
                    .addGap(77, 77, 77))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 872, Short.MAX_VALUE)
                    .addContainerGap())))
    );
    jPanel2Layout.setVerticalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel2Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(comboMostrar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(comboDr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4)
                        .addComponent(jLabel3))
                    .addGap(27, 27, 27)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(comboFechaFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(comboFechaInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2)
                        .addComponent(jLabel1)))
                .addComponent(btnBuscar))
            .addGap(21, 21, 21)
            .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(51, 51, 51)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel5)
                .addComponent(lblContador))
            .addContainerGap(245, Short.MAX_VALUE))
    );

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 902, Short.MAX_VALUE)
            .addContainerGap())
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap())
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 546, javax.swing.GroupLayout.PREFERRED_SIZE)
    );

    pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCancelarReservaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarReservaActionPerformed
        int resp =JOptionPane.showConfirmDialog(this, "Desea cancelar la reserva?", "Cancelación de reserva", JOptionPane.YES_NO_OPTION);
                if (resp == 0){
                    String codreserva = obtenerCodigoReserva();
                    cancelarReserva(codreserva);
                    limpiarTabla();
                    mostrarReservas();
                               }
    }//GEN-LAST:event_btnCancelarReservaActionPerformed

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        limpiarTabla();
        mostrarReservas();
    }//GEN-LAST:event_btnBuscarActionPerformed

    private void btnEditarReservaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarReservaActionPerformed
        /*reserva.codreserva=obtenerCodigoReserva();

        reserva.mostrarReserva(reserva.codreserva);

        String fechareserva = ""+tblReporte.getValueAt(tblReporte.getSelectedRow(), 0);
        String hora         = ""+tblReporte.getValueAt(tblReporte.getSelectedRow(), 1);
        //Formatea
        obtenerYEnviarAnhoMesDia(fechareserva);
        obtenerYEnviarHora(hora);

        reserva.setVisible(true);*/
        
        
        frmEditarCita n=new frmEditarCita(tblReporte.getValueAt(tblReporte.getSelectedRow(), 7).toString());
        n.setVisible(true);
    }//GEN-LAST:event_btnEditarReservaActionPerformed



    /*
     OBTIENE LA FECHA SELECCIONADA Y LA ENVIA
     PARTIDA EN DIA/MES/ANHO AL MÉTODO reserva.cambiarFecha(int d,int,m,int a) ,
     para setear la fecha en el calendario del frmReservaCita
     */
    public void obtenerYEnviarAnhoMesDia(String fechareserva){

            String dia="";
            String mes="";
            String anho="";

            StringTokenizer t=new StringTokenizer(fechareserva, "/");

            dia  = t.nextToken();
            mes  = t.nextToken();
            anho = t.nextToken();

            reserva.cambiarFecha(Integer.parseInt(anho), Integer.parseInt(mes)-1, Integer.parseInt(dia));

    }



    /*
     OBTIENE LA HORA SELECCIONADA Y LA ENVIA
      AL MÉTODO reserva.cambiarHoraCombo(hora,mins) ,
     para setear la hora en  frmReservaCita.

     */
    public void obtenerYEnviarHora(String h){
            
            String hora="";
            String mins="";
            

            StringTokenizer t=new StringTokenizer(h, ":");

            hora  = t.nextToken();
            mins  = t.nextToken();

            reserva.cambiarHoraCombo(hora, mins);
        
    }









    public void mostrarReservas(){
        
            String fechainicio = comboFechaInicio.getText();
            String fechafinal = comboFechaFinal.getText();
            String query = "";
            int op = comboMostrar.getSelectedIndex();
            int op2 = comboDr.getSelectedIndex();
            
           int idOdontologo = Integer.parseInt(odontologos.get(comboDr.getSelectedIndex()).elementAt(3).toString());

            switch (op) {
                case 0: query = " SELECT r.idReservaCita,r.fecha,p.nombres,p.apellidoPaterno,p.apellidoMaterno,p.telefono,p.celular,m.nombre,r.activoReservarCita from reservacita r, persona p,motivo m WHERE r.idPERSONA = p.idPERSONA "
                                + "AND r.fecha BETWEEN '"+validar.cambiarFormatoFechaParaBD(comboFechaInicio.getText())+" 00:00:00' AND '"+validar.cambiarFormatoFechaParaBD(comboFechaFinal.getText())+" 23:59:59' AND r.idMotivo = m.idMotivo AND r.Odontologo_id = "+idOdontologo    
                                +  " UNION SELECT r.idReservaCita,r.fecha,p.nombres,p.apellidoPaterno,p.apellidoMaterno,p.telefono,p.celular,m.nombre,r.activoReservarCita from reservacita r, persona p,paciente pa,motivo m "
                                +  "WHERE r.idPaciente = pa.idPaciente AND p.idPERSONA = pa.idPERSONA AND r.idMotivo = m.idMotivo "      
                                +  " AND r.fecha BETWEEN '"+validar.cambiarFormatoFechaParaBD(comboFechaInicio.getText())+" 00:00:00' AND '"+validar.cambiarFormatoFechaParaBD(comboFechaFinal.getText())+" 23:59:59' AND r.Odontologo_id = "+idOdontologo;
                        break;
                        
                            //case 1: query = "select p.nombres,p.apellidos,p.telefono,p.celular,r.Motivo,r.fecha,r.estado from RESERVACITA r,PERSONA p  where fecha > '" + fechainicio + "' and fecha < '" + fechafinal + " 23:59:59' and  p.id = r.idpersona and estado = 'Activa' and r.CMP = "+cmp +" order by fecha";break;

                            //case 2:query = query = "select p.nombres,p.apellidos,p.telefono,p.celular,r.Motivo,r.fecha,r.estado from RESERVACITA r,PERSONA p  where fecha > '" + fechainicio + "' and fecha < '" + fechafinal + " 23:59:59' and  p.id = r.idpersona and estado = 'Cancelada' and r.CMP = "+cmp +" order by fecha";break;
                            
                
                            }

                            
                            System.out.println(""+query);    

                            ControlReserva control=new ControlReserva();

                            
                           Vector<Vector> reporte =  control.listarReporte(query,1);
                           

                           for (int i = 0; i < reporte.size(); i++) {
                                   // tblReporte.setValueAt(reporte.get(i).elementAt(0), i, 2);
                                    tblReporte.setValueAt(reporte.get(i).elementAt(2), i, 3);
                                    tblReporte.setValueAt(reporte.get(i).elementAt(3), i, 4);
                                    tblReporte.setValueAt(reporte.get(i).elementAt(4), i, 5);                                    
                                    tblReporte.setValueAt(validar.obtenerHorarioDeCalendario(""+reporte.get(i).elementAt(1)), i, 1);
                                    tblReporte.setValueAt(validar.cambiarFormatoFecha(validar.obtenerDiaDeCalendario(""+reporte.get(i).elementAt(1))), i, 0);
                                    tblReporte.setValueAt(reporte.get(i).elementAt(6), i, 6);
                                    tblReporte.setValueAt(reporte.get(i).elementAt(0), i, 7);
                                                                    }
                      
                                        if (reporte.size()==0)
                                            JOptionPane.showMessageDialog(this, "No se encontraron reservas", "No existen reservas", JOptionPane.ERROR_MESSAGE);

                                          lblContador.setText(""+reporte.size());
                           
                                }





     public String obtenerCodigoReserva(){
                            String codigo="";
                             int n = tblReporte.getSelectedRow();
                             
                            // Obtenemos fecha y dia de la tabla . De la fila seleccionada.
                            String fecha = "" + tblReporte.getValueAt(n, 0);
                            String hora = "" + tblReporte.getValueAt(n, 1);
                            //validar.cambiarFormatoFecha(fecha);
                            String query = "select codreserva from RESERVACITA where fecha = '"+ fecha +" "+hora+"'";
                            

                            ControlReserva control=new ControlReserva();
                            Vector<Vector> reporte = control.listarReporte(query,0);


                            codigo = ""+reporte.get(0).elementAt(0);
                            
                          
                            return codigo;
                   }


                        public void cancelarReserva(String codreserva)               {
                                    /*Generamos un número random, y le adicionamos ms a la hora del query*/
                                        Random r = new Random();
                                        int ms = r.nextInt(999);

                                        // Obtenemos fecha y dia de la tabla . De la fila seleccionada.
                                        int n = tblReporte.getSelectedRow();
                                        String fecha = "" + tblReporte.getValueAt(n, 0);
                                        String hora = "" + tblReporte.getValueAt(n, 1);

                                        //Armamos fecha
                                        String fechacompleta = fecha +" "+hora+":00."+ms;

                                        System.out.println(fechacompleta);

                                        ControlReserva control=new ControlReserva();
                                        int cancelo =  control.editarReserva(codreserva,fechacompleta,1,1);

                                      if (cancelo == 1)
                                          JOptionPane.showMessageDialog(this, "La reserva ha sido cancelada", "Reserva cancelada", JOptionPane.INFORMATION_MESSAGE);

                                       



                                                                            }

         public void cargarOdontologos(){
            ControlOdontologo control=new ControlOdontologo();
             odontologos = control.listarTodos();


            for (int i = 0 ; i<odontologos.size(); i++){
                  comboDr.addItem(odontologos.get(i).elementAt(0)+" "+odontologos.get(i).elementAt(1));
            }


    }





public void limpiarTabla(){
       for (int i=0;i<tblReporte.getRowCount();i++){
                tblReporte.setValueAt("", i, 0);
                tblReporte.setValueAt("", i, 1);
                tblReporte.setValueAt("", i, 2);
                tblReporte.setValueAt("", i, 3);
                tblReporte.setValueAt("", i, 4);
                tblReporte.setValueAt("", i, 5);
                tblReporte.setValueAt("", i, 6);
                
       }
   }






    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {

                Visual.aspectoMac();
                new frmReporteReservas().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnCancelarReserva;
    private javax.swing.JButton btnEditarReserva;
    private javax.swing.JComboBox comboDr;
    private datechooser.beans.DateChooserCombo comboFechaFinal;
    private datechooser.beans.DateChooserCombo comboFechaInicio;
    private javax.swing.JComboBox comboMostrar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JLabel lblContador;
    private javax.swing.JTable tblReporte;
    // End of variables declaration//GEN-END:variables

}
